package net.jcip.examples.ReentrantLock;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ReentrantLockDemo {

    static ExecutorService executor = Executors.newFixedThreadPool(2);


    public static void main(String[] args){

        ReentrantLockAdd add = new ReentrantLockAdd(1);

        Runnable run1 = ()->{
            for(int p=0 ;p<100 ;p++){
                int i = add.nextInt();
                System.out.println("run1 add result:" + i);
            }
        };
        //如果我们需要获取任务结果或处理异常，就应该使用 submit()

        //另一方面，如果我们有一个不返回结果的任务，而我们又想触发它并忘记它，那么执行execute()就是正确的选择

        Runnable run2 = ()->{
            for(int p=0 ;p<100 ;p++){
                int i = add.nextInt();
                System.out.println("run2 add result:" + i);
            }
        };

        //execute用于执行
        executor.execute(run1);
        executor.execute(run2);

    }







}
